package com.javatest.redpacket.config;

import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;

import javax.servlet.MultipartConfigElement;
import javax.servlet.ServletRegistration;

/**
 * Created with IntelliJ IDEA.
 * Description:
 *
 * @author liuziyang
 * @create 2020 -08-03 22:05
 */
public class WebAppInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {

    /**
     * Spring IoC环境配置
     *
     * @return the class [ ]
     */
    @Override
    protected Class<?>[] getRootConfigClasses() {
        return new Class<?>[]{RootConfig.class};
    }

    /**
     * DispatchServlet环境配置
     * Get servlet config classes class [ ].
     *
     * @return the class [ ]
     */
    @Override
    protected Class<?>[] getServletConfigClasses() {
        return new Class<?>[]{WebConfig.class};
    }

    /**
     * DispatcherServlet拦截请求配置
     * Get servlet mappings string [ ].
     *
     * @return the string [ ]
     */
    @Override
    protected String[] getServletMappings() {
        return new String[]{"/"};
    }

    /**
     * Customize registration.
     *
     * @param registration the registration
     */
    @Override
    protected void customizeRegistration(ServletRegistration.Dynamic registration) {
        // 配置上传文件路径
        String filePath = "/home/lzy/Downloads";
        // 5MB
        Long singleMax = (long) (5 * Math.pow(2, 20));
        // 10MB
        Long totalMax = (long) (10 * Math.pow(2, 20));
        // 设置上传文件配置
        registration.setMultipartConfig(new MultipartConfigElement(filePath, singleMax, totalMax, 0));
    }
}
